package org.zp.util;

import java.util.regex.Pattern;

public class Validate {
	


	private String error;
	
	
	public boolean checkUserName(String userName) {
		if(null == userName) {
			error = "用户名不能为空";
			return false;
		}
		
		userName = userName.trim();
		
		if("".equals(userName)) {
			error = "用户名不能为空";
			return false;
		}
		
		if(userName.length()<=2) {
			error = "用户名不能小于2位";
			return false;
		}
		
		String regex = "^(?=((?=.*\\d)(?=.*[a-z]))|((?=.*\\d)(?=.*[A-Z]))|((?=.*\\d)(?=.*_))|((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*_))|((?=.*[A-Z])(?=.*_)))\\w{6,}$";
		if(!Pattern.matches(regex, userName)) {
			error = "用户名必须由6-20组成，切只能由数字、字母、下划线组成、首位必须是字母";
			return false;
		}
		return true;

	}
	
	public boolean checkTell(String tell) {
		if(null == tell) {
			error = "电话号码不能为空";
			return false;
		}
		
		tell = tell.trim();
		
		if("".equals(tell)) {
			error = "用户名不能为空";
			return false;
		}
		
		if(tell.length()<=2) {
			error = "用户名不能小于2位";
			return false;
		}
		
		String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
		if(!Pattern.matches(regex, tell)) {
			error = "手机号应为11位数";
			return false;
		}
		return true;

	}
	
	
	
	public boolean checkContent(String content) {
		if(null == content) {
			error = "地址内容不能为空";
			return false;
		}
		
		content = content.trim();
		
		if("".equals(content)) {
			error = "地址内容不能为空";
			return false;
		}
		
		if(content.length()<=1) {
			error = "地址内容不能小于1位";
			return false;
		}
		
		
		return true;

	}
	
	public boolean checkRealname(String content) {
		if(null == content) {
			error = "真实姓名不能为空";
			return false;
		}
		
		content = content.trim();
		
		if("".equals(content)) {
			error = "真实姓名不能为空";
			return false;
		}
		
		if(content.length()<=1) {
			error = "真实姓名不能小于1位";
			return false;
		}
		
		
		return true;

	}
	public boolean checkPassword(String content) {
		if(null == content) {
			error = "密码不能为空";
			return false;
		}
		
		content = content.trim();
		
		if("".equals(content)) {
			error = "密码不能为空";
			return false;
		}
		
		if(content.length()<=1) {
			error = "密码不能小于1位";
			return false;
		}
		
		
		return true;

	}
	
	
	
	public String getError() {
		return error;
	}


	public void setError(String error) {
		this.error = error;
	}
}
